package com.dingwei.superiordiary.mvp.presenter;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.MyCenterBean;
import com.dingwei.superiordiary.bean.NewNoticeMessageBean;
import com.dingwei.superiordiary.bean.UserDataBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.net.URL;

/**
 * @author Li Hao
 * Created by lihao on 2017/9/12.
 */

public class MinePresenter extends basePresenter {

    private Contract.MineView mineView;

    public MinePresenter(Contract.MineView view) {
        super(view);
        this.mineView = view;
    }

    public void getUserData() {
        RequestParams rp = new RequestParams(URLS.HOST+URLS.myCenter);
        rp.addBodyParameter("sessionid",BaseActivity.value.getToken());

        x.http().post(rp, new myCallback(BaseActivity.context, MyCenterBean.class) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                MyCenterBean bean = (MyCenterBean) baseBean;

                BaseActivity.value.setUserName(bean.data.nickname);
                BaseActivity.value.setHeadImg(bean.data.portrait);
                mineView.setUserData(bean);

            }

            @Override
            public void fail(FailsBean baseBean, String result) {

            }
        });
    }



    public void sign() {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.SIGN);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                showToast(baseBean.message);
                mineView.signSuccess();
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }


    public void newNoticeMessage() {
        RequestParams rp = new RequestParams(URLS.HOST+URLS.newNoticeMessage);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, NewNoticeMessageBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                NewNoticeMessageBean bean = (NewNoticeMessageBean) baseBean;
                mineView.setNewNoticeMessageBean(bean);

            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }
}
